from time import sleep
from pages.client_page.login_page import LoginPage


class LoginLogic():

    # 登录操作逻辑
    def login(self,driver,username,password,verif_code):
        # 1 .点击登录按钮
        driver.find_element(*LoginPage.login_link_elem).click()
        # 2. 输入用户名
        driver.find_element(*LoginPage.username_elem).send_keys(username)
        # 3. 输入密码
        driver.find_element(*LoginPage.password_elem).send_keys(password)
        # 4. 输入验证码
        driver.find_element(*LoginPage.verify_elem).send_keys(verif_code)
        # 5. 点击登录按钮
        driver.find_element(*LoginPage.login_button_elem).click()
        sleep(3)

    # 获取成功消息
    def get_login_success_msg(self,driver):
        return driver.find_element(*LoginPage.login_success_msg).text

    # 获取错误消息
    def get_error_msg(self,driver):
        return driver.find_element(*LoginPage.login_error_msg).text